package com.jw.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jw.response.Result;
import com.jw.system.entity.vo.DepartmentVO;
import com.jw.system.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author jw
 * @since 2021-04-20
 */
@RestController
@RequestMapping("/dept")
@Api(value = "系统部门模块", tags = "系统部门接口")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 所有部门
     *
     * @return
     */
    @ApiOperation(value = "所有部门")
    @GetMapping("/findAll")
    public Result findAll() {
        List<DepartmentVO> departmentVOS = deptService.findAllVO();
        return Result.ok().data("dept",departmentVOS);
    }

    /**
     * 获取部门列表
     * @return
     */
    @ApiOperation(value = "部门列表", notes = "模糊查询部门列表")
    @PostMapping("/getDeptList")
    public Result getDeptList(@RequestParam(value = "current", defaultValue = "1") Integer current,
                              @RequestParam(value = "size", defaultValue = "7") Integer size,
                              @RequestBody DepartmentVO dept) {
        Page<DepartmentVO> departmentVOS = deptService.getDeptList(current, size, dept);
        return Result.ok().data("dept",departmentVOS.getRecords()).data("total",departmentVOS.getTotal());
    }

}

